package com.kgc.scd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kgc.scd.bean.Comment;
import com.kgc.scd.bean.OrderItem;
import com.kgc.scd.bean.Product;
import com.kgc.scd.bean.ProductVO;
import com.kgc.scd.mapper.CommentMapper;
import com.kgc.scd.mapper.OrderItemMapper;
import com.kgc.scd.mapper.ProductMapper;
import com.kgc.scd.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: WangKuoKuo
 * @create: 2022-06-11 09:54
 * @description:
 **/
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private CommentMapper commentMapper;
    @Autowired
    private OrderItemMapper orderItemMapper;

    @Override
    public ProductVO queryProductById(String proId) {

        return productMapper.productById(proId);
    }

    @Override
    public int queryProductByIdCommentCount(String proId) {

        QueryWrapper<Comment> wrapper = new QueryWrapper<>();
        wrapper.eq("comm_proid",proId);

        return commentMapper.selectCount(wrapper);
    }

    @Override
    public int queryProductByIdBuyCount(String proId) {

        QueryWrapper<OrderItem> wrapper = new QueryWrapper<>();
        wrapper.eq("item_proid",proId);

        return orderItemMapper.selectCount(wrapper);
    }
}
